package com.demo.task.bean

import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import kotlinx.parcelize.Parcelize

@Parcelize
data class PlanBean(
    @SerializedName("area")
    val area: String?,
    @SerializedName("brightness")
    val brightness: Int, //亮度
    @SerializedName("pixelsh")
    val pixelsH: Int, //高
    @SerializedName("pixelsw")
    val pixelsW: Int, //宽
    @SerializedName("plan")
    var plan: List<Plan>?, //计划
    @SerializedName("snshow")
    val snShow: Int, //是否显示sn
    @SerializedName("softupdate")
    val softUpdate: Int,//升级 1
    @SerializedName("timeshow")
    val timeShow: Int,//是否显示时间
    @SerializedName("weathersync")
    val weatherSync: Int,//1 显示天气
    @SerializedName("trafficsync")
    val trafficSync: Int,//1 显示交通
    @SerializedName("weatherInfo")
    val weatherInfo: List<WeatherInfo>?, //天气数据
    @SerializedName("traffic")
    var trafficInfo: List<TrafficInfo>?,//交通数据
    @SerializedName("ispixels")
    var isPixels: Int, // 1发送数据包
    @SerializedName("inid")
    var inId: Int, // 数据包相关
    @SerializedName("innum")
    var inNum: Int, // 数据包相关
    @SerializedName("plancontrol")
    var planControl: List<PlanControl>?, //控制计划
    @SerializedName("upgrade")
    var upgrade: Upgrade?, //升级数据
    @SerializedName("isnow")
    var isNow: Int,//1
    @SerializedName("signalshow")
    var signalShow: Int?,//1
) : Parcelable {
    @Parcelize
    data class Plan(
        @SerializedName("enddate")
        val endDate: String,
        @SerializedName("endtime")
        val endTime: String,
        @SerializedName("group")
        val group: List<Group>,
        @SerializedName("id")
        val id: Int,
        @SerializedName("startdate")
        val startDate: String,
        @SerializedName("starttime")
        val startTime: String
    ) : Parcelable {
        @Parcelize
        data class Group(
            @SerializedName("height")
            val height: Int,
            @SerializedName("id")
            val id: Int,
            @SerializedName("pages")
            val pages: List<Page>,
            @SerializedName("width")
            val width: Int
        ) : Parcelable {
            @Parcelize
            data class Page(
                @SerializedName("box")
                val box: List<Box>,
                @SerializedName("id")
                val id: Int,
                @SerializedName("repeat")
                val repeat: Int
            ) : Parcelable {
                @Parcelize
                data class Box(
                    @SerializedName("id")
                    val id: String,
                    @SerializedName("list")
                    val list: List<Window>,
                    @SerializedName("pixelsh")
                    val pixelsH: Int,
                    @SerializedName("pixelsw")
                    val pixelsW: Int,
                    @SerializedName("title")
                    val title: String,
                    @SerializedName("x")
                    val x: Int,
                    @SerializedName("y")
                    val y: Int,

                    @Transient
                    var uid: String? = "",
                    @Transient
                    var flag: Boolean = true
                ) : Parcelable {
                    // 原代码此处类名缺失，假设类名为 AnotherClass
                    @Parcelize
                    data class Window(
                        @SerializedName("attaid")
                        val attaId: Int,
                        @SerializedName("content")
                        val content: String,
                        @SerializedName("hold")
                        private val _hold: Int,  // 改为私有后备字段
                        @SerializedName("id")
                        val id: String,
                        @SerializedName("qty")
                        var qty: Int,
                        @SerializedName("sha1")
                        val sha1: String?,
                        @SerializedName("sort")
                        val sort: Int,
                        @SerializedName("type")
                        val type: Int,
                        @SerializedName("volume")
                        val volume: Int
                    ) : Parcelable {
                        val hold: Int
                            get() = if (_hold > 0) _hold else 5
                    }
                }
            }
        }
    }

    @Parcelize
    data class WeatherInfo(
        @SerializedName("adcode")
        val adCode: String,
        @SerializedName("city")
        val city: String,
        @SerializedName("humidity")
        val humidity: String,
        @SerializedName("humidity_float")
        val humidityFloat: String,
        @SerializedName("province")
        val province: String,
        @SerializedName("reporttime")
        val reportTime: String,
        @SerializedName("temperature")
        val temperature: String,
        @SerializedName("temperature_float")
        val temperatureFloat: String,
        @SerializedName("weather")
        val weather: String,
        @SerializedName("winddirection")
        val windDirection: String,
        @SerializedName("windpower")
        val windPower: String
    ) : Parcelable

    @Parcelize
    data class TrafficInfo(
        @SerializedName("description")
        val description: String?,
        @SerializedName("evaluation")
        val evaluation: Evaluation
    ) : Parcelable {
        @Parcelize
        data class Evaluation(
            @SerializedName("blocked")
            val blocked: String?,
            @SerializedName("congested")
            val congested: String?,
            @SerializedName("description")
            val description: String?,
            @SerializedName("expedite")
            val expedite: String?,
            @SerializedName("status")
            val status: String?,
        ) : Parcelable
    }

    @Parcelize
    data class PlanControl(
        @SerializedName("id")
        val id: Int,
        @SerializedName("bns")
        val bns: Int?,
        @SerializedName("ctr")
        val ctr: Int?,
        @SerializedName("dam")
        val dam: Int?,
        @SerializedName("enddate")
        val endDate: String,
        @SerializedName("endtime")
        val endTime: String,
        @SerializedName("startdate")
        val startDate: String,
        @SerializedName("starttime")
        val startTime: String,
        @SerializedName("tem")
        val tem: Int?,
        @SerializedName("vol")
        val vol: Int?,
    ) : Parcelable

    @Parcelize
    data class Upgrade(
        @SerializedName("androidv")
        val baseVersion: String,
        @SerializedName("url")
        val url: String,
        @SerializedName("version")
        val updateVersion: String
    ) : Parcelable

    fun isSamePlan(list: List<Plan>?): Boolean {
        // 首先检查传入的列表是否为空或者与当前对象的 plan 列表大小不同
        if (list.isNullOrEmpty() || this.plan?.size != list.size) {
            return false
        }

        val ids1 = list.map { it.id }.toSet()
        val ids2 = this.plan?.map { it.id }?.toSet()
        return ids1 == ids2
    }
}